package com.scuec.groupfive.Controller;

import com.scuec.groupfive.entity.UserAccountAge;
import com.scuec.groupfive.service.UserAccountAgeService;
import com.scuec.groupfive.vo.UserAccountAgeVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/insistence-time")
public class InsistenceTimeController {

    @Autowired
    private UserAccountAgeService userAccountAgeService;

    @GetMapping("/user/{userId}")
    public UserAccountAgeVO getUserAccountAge(@PathVariable Integer userId) {
        UserAccountAgeVO result = new UserAccountAgeVO();
        try {
            UserAccountAge userAccountAge = userAccountAgeService.getUserAccountAge(userId);
            if (userAccountAge != null) {
                BeanUtils.copyProperties(userAccountAge, result);
                result.setMessage("查询成功");
            } else {
                result.setMessage("未找到该用户");
            }
        } catch (Exception e) {
            result.setMessage("查询失败：" + e.getMessage());
        }
        return result;
    }
}